package com.example.ware.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.common.to.es.SkuHasStockTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.example.ware.entity.WmsWareSkuEntity;
import com.example.ware.service.WmsWareSkuService;
import com.common.utils.PageUtils;
import com.common.utils.R;



/**
 * 商品库存
 *
 * @author WDL
 * @email 2329156214@QQ.com
 * @date 2022-05-01 16:31:00
 */
@RestController
@RequestMapping("gmallware/waresku")
public class WmsWareSkuController {
    @Autowired
    private WmsWareSkuService wmsWareSkuService;


    @PostMapping("/hasStock")
    public R<SkuHasStockTo> hasStock(@RequestBody List<Long> skuIds) {

        List<SkuHasStockTo> list = wmsWareSkuService.hasStock(skuIds);
        return new R(list);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
//        PageUtils page = wmsWareSkuService.queryPage(params);
        PageUtils page = wmsWareSkuService.queryPageBySkuIdAndWare(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		WmsWareSkuEntity wmsWareSku = wmsWareSkuService.getById(id);

        return R.ok().put("wmsWareSku", wmsWareSku);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody WmsWareSkuEntity wmsWareSku){
		wmsWareSkuService.save(wmsWareSku);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody WmsWareSkuEntity wmsWareSku){
		wmsWareSkuService.updateById(wmsWareSku);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		wmsWareSkuService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }


}
